Skip to content

feat(test): support glob patterns in --namespace#1321

Open
alliasgher wants to merge 1 commit into
open-policy-agent:masterfrom
alliasgher:feat-namespace-wildcard
Open

feat(test): support glob patterns in --namespace#1321
alliasgher wants to merge 1 commit into
open-policy-agent:masterfrom
alliasgher:feat-namespace-wildcard

Conversation

@alliasgher

Copy link
Copy Markdown

Allow `--namespace` to accept glob patterns (`*`, `?`, character classes) so
users with hierarchical Rego packages can match families of namespaces in
one flag, e.g.:

```
conftest test --namespace 'k8s.simple.*' deployment.yaml
```

Behaviour

  • Patterns are matched against the namespaces actually loaded into the
    engine using `path.Match` semantics, with `.` treated as the segment
    separator. So `k8s.simple.*` matches `k8s.simple.deployment`,
    `k8s.simple.hpa`, etc., but not `k8s.simple.deployment.foo`.
  • Literal namespaces pass through unchanged, and they can be mixed with
    globs (`--namespace main --namespace 'k8s.simple.*'`).
  • A pattern that doesn't match any loaded namespace errors out, so typos
    don't silently turn into a no-op.
  • `--all-namespaces` is unaffected.

Tests

`runner/test_test.go` covers the `hasGlob` predicate and the
`expandNamespaceGlobs` expansion, including dedup, mixed literals/globs,
char classes, and the unmatched-pattern error.

Fixes #1141

Allow --namespace to accept glob patterns (`*`, `?`, character classes)
so users with hierarchical Rego packages can match families of namespaces
in one flag, e.g. --namespace k8s.simple.*.

Patterns are expanded against the namespaces actually loaded into the
engine, with literals passing through unchanged. An unmatched pattern
errors so typos do not silently turn into a no-op.

Fixes open-policy-agent#1141

Signed-off-by: alliasgher <alliasgher123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request: Support wildcards in --namespace

1 participant